package com.test.util;


/**
 * 平台相关的功能
 * 
 * @author zhuyanchao
 * @version 1.0
 */
public class PlatformOption {

	/**
	 * 获取行分隔符
	 * @return
	 */
	public static String getLineSeparator() {
		String lineSeparator = null;
		if (lineSeparator != null)
			return lineSeparator;
		else {
			lineSeparator = System.getProperty("line.separator");
			if (lineSeparator == null) {

				String os = System.getProperty("os.name").toLowerCase();
				if (os.indexOf("mac") > -1) {/* mac */
					lineSeparator = "\r";
				} else if ((os.indexOf("windows 9") > -1)
						|| (os.indexOf("nt") > -1)
						|| (os.indexOf("windows 2000") > -1)
						|| (os.indexOf("windows xp") > -1)
						|| (os.indexOf("windows 2003") > -1)) {
					lineSeparator = "\r\n";
				} else {/* linx, unix */
					lineSeparator = "\n";
				}

			}
		}
		return lineSeparator;
	}
	public static byte[] getUTF8Bytes(String inputString) {
		String encoding = System.getProperty("file.encoding");
		if (encoding == null) {
			encoding = "ISO8859_1";
		}
		byte[] outputByte = null;
		try {
			if (encoding.equalsIgnoreCase("UTF-8")) {
				outputByte = inputString.getBytes();
			} else {
				String tmp = new String(inputString.getBytes(), "UTF-8");
				outputByte = tmp.getBytes("UTF-8");
			}
		} catch(Exception e) {
			outputByte = new byte[0];
		}
		return outputByte;
		
	}
}
